package 链表与双指针.m02d28.t01;

class ListNode {
    int val;
    ListNode next;

    ListNode(int x) {
        val = x;
        next = null;
    }
}

public class Solution {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode res = null, A = headA, B = headB;
        while (A != B) {
            if (A == null) {
                A = headB;
            } else {
                A = A.next;
            }
            if (B == null) {
                B = headA;
            } else {
                B = B.next;
            }

        }
        res = A;
        return res;
    }
}